﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeChatBotSDK.JsonEx;

namespace WeChatBotSDK.Models.EventCallback
{
    /// <summary>
    /// 支付事件数据类
    /// </summary>
    public class PaymentEventData : IWeChatEventData
    {
        /// <summary>
        /// 收到这条消息的13位时间戳
        /// </summary>
        [JsonPropertyName("timeStamp")]
        public long TimeStamp { get; set; }

        /// <summary>
        /// 消息来源类型
        /// 1=私聊，2=群聊，3=公众号
        /// </summary>
        [JsonConverter(typeof(StringToEnumConverter<FromType>))]
        [JsonPropertyName("fromType")]
        public FromType FromType { get; set; }

        /// <summary>
        /// 消息类型
        /// </summary>
        [JsonConverter(typeof(StringToEnumConverter<MsgType>))]
        [JsonPropertyName("msgType")]
        public MsgType MsgType { get; set; }

        /// <summary>
        /// 消息来源
        /// 0=别人发送，1=自己手机发送
        /// </summary>
        [JsonConverter(typeof(StringToEnumConverter<MsgSourceEnum>))]
        [JsonPropertyName("msgSource")]
        public MsgSourceEnum MsgSource { get; set; }

        /// <summary>
        /// 对方微信 ID
        /// 当 fromType=1 时为好友 wxid，
        /// 当 fromType=2 时为群 wxid，
        /// 当 fromType=3 时为公众号 wxid
        /// </summary>
        [JsonPropertyName("fromWxid")]
        public string FromWxid { get; set; }

        /// <summary>
        /// 当 fromType=2 时有效，为群内发言人 wxid
        /// </summary>
        [JsonPropertyName("finalFromWxid")]
        public string FinalFromWxid { get; set; }

        /// <summary>
        /// 当 fromType=2 且 msgSource=0 时有效，为消息中 @人的 wxid 列表
        /// </summary>
        [JsonPropertyName("atWxidList")]
        public List<string> AtWxidList { get; set; }

        /// <summary>
        /// 当 fromType=2 时有效
        /// </summary>
        //[JsonConverter(typeof(IntConverter))]
        [JsonPropertyName("silence")]
        public int Silence { get; set; }

        /// <summary>
        /// 当 fromType=2 时有效，为群成员数量
        /// </summary>
        //[JsonConverter(typeof(IntConverter))]
        [JsonPropertyName("membercount")]
        public int MemberCount { get; set; }

        /// <summary>
        /// 消息签名
        /// </summary>
        [JsonPropertyName("signature")]
        public string Signature { get; set; }

        /// <summary>
        /// 消息内容
        /// </summary>
        [JsonPropertyName("msg")]
        public string Msg { get; set; }

        /// <summary>
        /// 获取收到消息的时间戳的日期时间格式
        /// </summary>
        [JsonIgnore(Condition = JsonIgnoreCondition.Always)] 
        public DateTime ReceivedTime => DateTimeOffset.FromUnixTimeMilliseconds(TimeStamp).DateTime;
    }
}
